<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Changepassword extends CI_Controller{

  public function __construct()
  {
    parent::__construct();
    //Codeigniter : Write Less Do More
    $this->load->model('User_model', 'users');
    $this->load->model('Operation_model', 'oper');
    if(empty($_SESSION['id'])){
      echo "0";
      echo "<script src='/static/js/jquery.min.js?v=2.1.4'></script>";
      echo "<script src='/static/js/layer/layer.js'></script>";
      echo "<script>layer.msg('你还没有登录，请先登录',{icon:2});setTimeout(function(){window.location.href='/login';},1500)</script>";
      exit;
    }
  }

	function index()
	{
	    $this->load->view('changepassword');
	}

	public function editChangeLoginPwd(){
		if($this->users->changeUserInfo(array('id'=>$_SESSION['id']),array('password'=>substr(md5($this->input->post('password')), 8, 16)))){
			//添加操作日志
			$this->oper->add(array(
				'operation'=>'修改登录密码',
				'ip'=> $this->input->ip_address(),
				'uid'=>$_SESSION['id'],
				'time'=> date('Y-m-d h:i:s',time())
			));

			foreach ($_SESSION as $key => $value) {
				unset($_SESSION[$key]);
			}
			jechos("修改登录密码成功");
		}else{
			$this->oper->add(array(
				'operation'=>'修改登录失败',
				'ip'=> $this->input->ip_address(),
				'uid'=>$_SESSION['id'],
				'time'=> date('Y-m-d h:i:s',time())
			));
			jechof("修改登录密码失败");
		}
	}

}
